package com.jspm;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.awt.*;
import java.net.URI;

@SpringBootApplication( exclude = {TransactionAutoConfiguration.class})// 禁用默认事务配置
//@EnableTransactionManagement // 启用事务管理
@MapperScan("com.jspm.dao") // 指定 Dao 接口所在的包
public class JspmApplication {

    public static void main(String[] args) {
        SpringApplication.run(JspmApplication.class, args);
        openBrowser();
    }

    private static void openBrowser() {
        try {
            // 等待应用完全启动（可根据实际情况调整延迟）
            Thread.sleep(1000);

            String url = "http://localhost:8080/jspm74bb5/front/index.jsp"; // 默认首页地址
            if(Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if(desktop.isSupported(Desktop.Action.BROWSE)) {
                    desktop.browse(new URI(url));
                }
            } else {
                Runtime runtime = Runtime.getRuntime();
//                runtime.exec("xdg-open " + url);  // Linux
                // 或 runtime.exec("open " + url);  // Mac
                 runtime.exec("cmd /c start " + url);  // Windows
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
